Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(proto)!: remove optional fields in protos #2940

Closed
wants to merge 1 commit into from

Conversation

conorsch
Copy link
Contributor

@conorsch conorsch commented Aug 16, 2023

The cosmos fork of gogoproto, used to generate golang code from BSR, doesn't support "optional" fields in proto3 syntax. Rather than sort that out, we're removing use of optional to unblock integration work on interchaintest.

In order to preserve the representation of optionality, we use submessages in the proto types, so we can include or omit the named field. A notable exception is for encrypted memos: since the encrypted memo payload must be a specific length, we can check for whether it's empty, and map an empty encrypted memo to None.

H/t to @plaidfinch for describing the submessage pattern to me, and implementing it on the governance changes.

Closes #2933.

@conorsch conorsch force-pushed the no-optional-fields-in-protos branch from 15afac0 to 1d967c3 Compare August 16, 2023 21:04
@conorsch conorsch force-pushed the no-optional-fields-in-protos branch from 1d967c3 to 2515c42 Compare August 17, 2023 15:52
@conorsch conorsch force-pushed the no-optional-fields-in-protos branch from 2515c42 to 493c561 Compare August 17, 2023 20:06
@conorsch conorsch force-pushed the no-optional-fields-in-protos branch from 493c561 to dc71918 Compare August 17, 2023 20:18
@conorsch conorsch force-pushed the no-optional-fields-in-protos branch from dc71918 to 91070cd Compare August 17, 2023 23:19
@conorsch conorsch force-pushed the no-optional-fields-in-protos branch from 91070cd to b28c185 Compare August 18, 2023 15:16
@conorsch conorsch force-pushed the no-optional-fields-in-protos branch from b28c185 to d1bc8ec Compare August 18, 2023 18:04
@conorsch conorsch force-pushed the no-optional-fields-in-protos branch from 1c3dd33 to 78bd2c3 Compare August 18, 2023 21:03
@conorsch conorsch force-pushed the no-optional-fields-in-protos branch from 7a9c6a7 to 843da8d Compare August 18, 2023 23:00
@conorsch conorsch changed the title feat!(proto) remove optional fields in protos feat(proto)!: remove optional fields in protos Aug 18, 2023
The cosmos fork of gogoproto, used to generate golang code from BSR,
doesn't support "optional" fields in proto3 syntax. Rather than sort
that out, we're removing use of optional to unblock integration work on
interchaintest.

In order to preserve the representation of optionality, we use
submessages in the proto types, so we can include or omit the named
field. A notable exception is for encrypted memos: since the encrypted memo
payload must be a specific length, we can check for whether it's empty,
and map an empty encrypted memo to None.

H/t to @plaidfinch for describing the submessage pattern to me,
and implementing it on the governance changes.

Closes #2933.
@conorsch conorsch force-pushed the no-optional-fields-in-protos branch from 843da8d to 04888f1 Compare August 18, 2023 23:07
@conorsch conorsch temporarily deployed to smoke-test August 18, 2023 23:07 — with GitHub Actions Inactive
@conorsch conorsch marked this pull request as ready for review August 19, 2023 00:09
Comment on lines +221 to +226
Commit commit = 1;
}

// The sha1 hash of a git commit, used to indicate a specific version of the software.
message Commit {
string commit = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, this could just be string commit = 1 rather than a submessage, with the empty string meaning None.

Comment on lines +93 to +100

message UnbondingEpoch {
// The epoch in which stake becomes unbonded.
uint64 epoch = 1;
}

// Present if needed to specify unbonding epoch.
UnbondingEpoch unbonding_epoch = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also just have uint64 unbonding_epoch = 2, since 0 is not a valid unbonding epoch.

Comment on lines +131 to +132
// Identifies the account group to query. Defaults to 0.
core.crypto.v1alpha1.AccountGroupId account_group_id = 14;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 isn't a valid account group ID, right? So this comment should read

// If present, identifies the account group to query.

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could just drop these entirely, since we don't use them at all and have no concrete plans to do multi-account view servers.

Comment on lines +421 to +428
// Submessage to represent optionality for specifying heights.
message BlockHeight {
uint64 height = 1;
}
// If present, return only transactions after this height.
optional uint64 start_height = 1;
BlockHeight start_height = 1;
// If present, return only transactions before this height.
optional uint64 end_height = 2;
BlockHeight end_height = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than defining a submessage, these should just be uint64 start_height and uint64 end_height, since 0 is not a valid block height.

Comment on lines +432 to +437
// Submessage to represent optionality for block height.
message BlockHeight {
uint64 height = 1;
}
// The height the transaction was included in a block, if known.
optional uint64 height = 1;
BlockHeight height = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto above, this should just be a uint64.

Comment on lines +484 to +485
// Present if the note was spent, otherwise absent.
BlockHeight height_spent = 6;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto above, this should just be a uint64.

Comment on lines +502 to +504

// If present, height at which Swap was claimed.
BlockHeight height_claimed = 6;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto above, this should just be a uint64.

@hdevalence
Copy link
Member

This PR changes a lot of scalar fields to have submessages, but in almost every case it would be simpler and easier (as well as less work, for ourselves making this change as well as all downstream users) to just use ordinary values.

@conorsch
Copy link
Contributor Author

This PR changes a lot of scalar fields to have submessages, but in almost every case it would be simpler and easier (as well as less work, for ourselves making this change as well as all downstream users) to just use ordinary values.

Great feedback, thanks for thorough review. I've opened a separate PR, #2951, with a fresh implementation as you describe.

@conorsch
Copy link
Contributor Author

Superseded by #2951.

@conorsch conorsch closed this Aug 21, 2023
@cratelyn cratelyn added the protobuf-changes Makes changes to the protobuf definitions. label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
protobuf-changes Makes changes to the protobuf definitions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove optional fields throughout protos
4 participants